﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;

namespace Noria.Core
{
    static class Extention
    {
        public static IEnumerable<AutomationElement> GetNativeChildren(this AutomationElement e, string className)
        {
            List<AutomationElement> list = new List<AutomationElement>();

            int hRoot = e.Current.NativeWindowHandle;
            int hChild = 0;

            while (true)
            {
                hChild = NativeMethods.FindWindowExW(hRoot, hChild, className, null);
                if (hChild == 0)
                    break;
                else
                    list.Add(AutomationElement.FromHandle((IntPtr)hChild));
            }

            return list;
        }
    }
}
